package com.diyunapp.xilinapp.base;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.selfdefine.SystemBarTintManager;
import com.kaopiz.kprogresshud.KProgressHUD;
import com.nuttysoft.nutand.activity.NaBaseActivity;

/**
 * Created by Administrator on 2016/6/17.
 */
public class BaseActivity extends NaBaseActivity {

    public KProgressHUD hub;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getTopBar().setRightIconRightMargin(16);
        getTopBar().getLeftIcon().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        getTopBar().getRightIcon().setVisibility(View.GONE);

        hub = KProgressHUD.create(this)
                .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
                .setCancellable(true)
                .setAnimationSpeed(2)
                .setDimAmount(0.5f);
        if (android.os.Build.VERSION.SDK_INT > 18)
        {
            Window window = getWindow();
            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

            window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            // 创建状态栏的管理实例
            SystemBarTintManager tintManager = new SystemBarTintManager(this);
            // 激活状态栏设置
            tintManager.setStatusBarTintEnabled(true);
            // 激活导航栏设置
            tintManager.setNavigationBarTintEnabled(true);
            // 设置一个颜色给系统栏
            tintManager.setTintColor(getResources().getColor(R.color.domain_orange));
        }
    }

    public void nextAct(Class act){
        Intent intent = new Intent();
        intent.setClass(this, act);
        startActivity(intent);
    }

    public void toast(String msg){
        Toast.makeText(this,msg,Toast.LENGTH_SHORT).show();
    }

    public void showLoading(){
        hub.show();
    }

    public void dismissLoading(){
        hub.dismiss();
    }
}

